// Thud - a dynamic object-oriented language
// Copyright (C) 2009,2010 David H. Hovemeyer <david.hovemeyer@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*
 * MapCommandLine.cpp
 *
 *  Created on: Jan 6, 2010
 *      Author: dhovemey
 */

#include "util/String.h"
#include "util/MapCommandLine.h"

MapCommandLine::MapCommandLine()
{

}

MapCommandLine::MapCommandLine(const char *options)
	: CommandLine(options)
{

}

MapCommandLine::~MapCommandLine()
{

}

bool MapCommandLine::hasOption(const std::string &name) const
{
	return m_chosenOptionMap.find(name) != m_chosenOptionMap.end();
}

std::string MapCommandLine::getOptionArg(const std::string &name) const
{
	ChosenOptionMap::const_iterator i = m_chosenOptionMap.find(name);
	if (i == m_chosenOptionMap.end()) {
		throw CommandLineException(L"Option " + String::fromUtf8(name) + L" is not set");
	}
	return (*i).second;
}

void MapCommandLine::handleSwitch(const std::string &name)
{
	m_chosenOptionMap[name] = ""; // just add an empty string as the "argument"
}

void MapCommandLine::handleOption(const std::string &name, const std::string &arg)
{
	m_chosenOptionMap[name] = arg;
}
